Skip to content

feature: skip the openjdk install when the JVM is already on the image - #248

Merged
andrzej-janczak merged 2 commits into
masterfrom
skip-jdk-install
Aug 20, 2026
Merged

feature: skip the openjdk install when the JVM is already on the image#248
andrzej-janczak merged 2 commits into
masterfrom
skip-jdk-install

Conversation

@andrzej-janczak

@andrzej-janczak andrzej-janczak commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Problem: every sbt job spent ~44 MB and tens of seconds on apt install openjdk-N-jre.
The machine images already carry JDK 8, 17 and 21, so apt was only upgrading a package
that was already installed.

Fix: install only when the requested JVM is not already registered, and always switch
the default. JDK 11 is the only version genuinely missing from the images.

Trade-off: the build JDK now stays at the image's patch level, so CI stops picking up
Java security updates. Acceptable for a build box; runtime images are unaffected and
keep their newer CVE-patched versions. Probe: codacy-events pipeline #971.

Problem: every sbt job spends ~44 MB and tens of seconds on `apt install
openjdk-N-jre`. The machine images already carry JDK 8, 17 and 21, so apt was
only upgrading an installed package (17.0.13 -> 17.0.15 on ubuntu-2004).
Fix: install only when the JVM directory is absent, and always switch the
default. JDK 11 is the only version genuinely missing from the images.
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

@codacy-production codacy-production Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

The PR correctly implements an optimization to skip OpenJDK installation when the target version is already present on the image, which should result in faster build times. Codacy analysis indicates the code is up to standards.

However, a portability issue was identified: the path used for the JVM check is hardcoded to amd64. This will cause the check to fail on ARM-based executors (e.g., CircleCI's arm.medium resource class), leading to unnecessary re-installation attempts and potential pathing errors in the update-alternatives step.

Test suggestions

  • Verify that installation is skipped when the target JDK directory exists.
  • Verify that 'apt update' and 'apt install' are triggered when the target JDK directory is missing.
  • Verify that the default Java version is updated correctly in both the skip and install paths.
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Verify that installation is skipped when the target JDK directory exists.
2. Verify that 'apt update' and 'apt install' are triggered when the target JDK directory is missing.
3. Verify that the default Java version is updated correctly in both the skip and install paths.

TIP Improve review quality by adding custom instructions
TIP How was this review? Give us feedback

Comment thread src/jobs/sbt.yml
sudo apt update
sudo apt install openjdk-${OJDK_VERSION}-jre
sudo update-alternatives --set java /usr/lib/jvm/java-${OJDK_VERSION}-openjdk-amd64/bin/java
JVM_DIR="/usr/lib/jvm/java-${OJDK_VERSION}-openjdk-amd64"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 MEDIUM RISK

The JVM path is hardcoded to amd64, which breaks compatibility with ARM-based executors. Use dpkg --print-architecture to dynamically determine the correct path for the host architecture.

Suggested change
JVM_DIR="/usr/lib/jvm/java-${OJDK_VERSION}-openjdk-amd64"
JVM_DIR="/usr/lib/jvm/java-${OJDK_VERSION}-openjdk-$(dpkg --print-architecture)"

@andrzej-janczak andrzej-janczak Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not applying. -amd64 was already on the original line 94; this diff only moves it into a variable.

ARM is unreachable here: machine.yml fixes resource_class: large and sbt.yml has no resource_class param. The orb has 8 other amd64 hardcodes, so fixing one implies ARM works when it does not. Own ticket if we ever want it.

A directory can exist without update-alternatives knowing about it, and the
--set below would then fail. Testing the alternative tests the actual
precondition.
@andrzej-janczak
andrzej-janczak merged commit c308fa7 into master Aug 20, 2026
6 checks passed
@andrzej-janczak
andrzej-janczak deleted the skip-jdk-install branch August 20, 2026 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants